Typestate analysis